<?php 
header("content-type:text/html;charset=utf-8");
$file = $_FILES['file'];
// print_r($file);die();
$pdo = new PDO("mysql:host=127.0.0.1;dbname=lx","root","root");
include_once("/Classes/PHPExcel.php");
$excel = PHPExcel_IOFactory::load($file['tmp_name']);
$sheet = $excel -> getActiveSheet();
// print_r($sheet);

$rows = $sheet->getHighestRow();
// print_r($rows);
$cols = $sheet->gethighestColumn();
// print_r($cols);
for ($i=2; $i <=$rows ; $i++) { 
	for ($j='A'; $j <=$cols ; $j++) { 
		$data[$i-2][] = $sheet->getCell($j.$i)->getValue();
	}
}
// print_r($data);
foreach ($data as $key => $value) {
	$name = $value[0];
	$pwd = $value[1];
	$age = $value[2];
	$sql = "insert into users values('','$name','$pwd','$age')";
	$res = $pdo -> exec($sql);

}
if ($res) {
	echo "<script>alert('表格导入成功');location.href='show.php';</script>";
}else{
	echo "<script>alert('表格导入失败');</script>";
}





 ?>